package br.ufg.inf.tag;

import br.ufg.inf.musica.Musica;
import br.ufg.inf.servlet.Servlet;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TagController extends Servlet {

  
    public void listar(HttpServletRequest req, HttpServletResponse res) throws Exception {
        TagDAO tagDAO = new TagDAO();

        ArrayList<Tag> listaTag = tagDAO.listar();
     
        req.setAttribute("listaTags", listaTag);

        RequestDispatcher rd = req.getRequestDispatcher("home.jsp");
        rd.forward(req, res);
    }

    public void ver(HttpServletRequest req, HttpServletResponse res) throws Exception {
        TagDAO tagDAO = new TagDAO();


        Tag tag = tagDAO.obter(Integer.parseInt(req.getParameter("id_tag")));

       
        req.setAttribute("tag", tag);

        RequestDispatcher rd = req.getRequestDispatcher("musicas_tag.jsp");
        rd.forward(req, res);
    }
    
    public void avaliar(HttpServletRequest req, HttpServletResponse res) throws Exception {
        TagDAO tagDAO = new TagDAO();
        
        if(req.getParameter("avaliar").equals("dislike")){
            tagDAO.dislike(Integer.parseInt(req.getParameter("id_tag")),Integer.parseInt(req.getParameter("id_musica")));
        }else{
            tagDAO.like(Integer.parseInt(req.getParameter("id_tag")),Integer.parseInt(req.getParameter("id_musica")));
        }
        RequestDispatcher rd = req.getRequestDispatcher("/Music4Me/Servlet?modulo=musica&acao=ver&id_musica="+req.getParameter("id_musica")+"&id_tag="+req.getParameter("id_tag"));
        rd.forward(req, res);
    }
}
